Add typed builder API for vector search index definitions#1960
Draft
rozza wants to merge 1 commit intomongodb:mainfrom
Draft
Add typed builder API for vector search index definitions#1960rozza wants to merge 1 commit intomongodb:mainfrom
rozza wants to merge 1 commit intomongodb:mainfrom
Conversation
* Introduced SearchIndexDefinition sealed interface with factory methods, * VectorSearchIndexFields (vectorField, filterField, autoEmbedField builders), * HnswSearchIndexOptions for HNSW-specific parameters, and * VectorSearchIndexDefinition as the concrete implementation. Updates * Updated SearchIndexModel javadoc to reference the new builders. JAVA-6112
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a typed Java builder API for creating Atlas Vector Search index definitions (and supporting options), and wires the new public types into the Scala driver surface area. It also adds unit tests validating the BSON produced by the new builders.
Changes:
- Added
SearchIndexDefinitionwithvectorSearch(...)factory methods and a concreteVectorSearchIndexDefinitionimplementation. - Added
VectorSearchIndexFieldsbuilders (vector/filter/auto-embed fields) andHnswSearchIndexOptionsfor HNSW parameters. - Updated
SearchIndexModelJavadoc and added unit tests covering common definition shapes and BSON output.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| driver-scala/src/main/scala/org/mongodb/scala/model/package.scala | Exposes new Java model types to Scala via type aliases. |
| driver-core/src/test/unit/com/mongodb/client/model/SearchIndexDefinitionTest.java | Adds unit tests asserting BSON output for the new vector index definition builders. |
| driver-core/src/main/com/mongodb/client/model/VectorSearchIndexFields.java | Introduces fluent builders for vector search index field definitions. |
| driver-core/src/main/com/mongodb/client/model/VectorSearchIndexDefinition.java | Implements a SearchIndexDefinition producing { fields: [...] }. |
| driver-core/src/main/com/mongodb/client/model/SearchIndexModel.java | Updates Javadoc to reference the new vector index definition builders. |
| driver-core/src/main/com/mongodb/client/model/SearchIndexDefinition.java | Adds a sealed interface + factories for typed search index definitions (currently vector search). |
| driver-core/src/main/com/mongodb/client/model/HnswSearchIndexOptions.java | Adds a small fluent builder for HNSW-specific options, implementing Bson. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+484
to
+506
| /** | ||
| * A definition for an Atlas Search index. | ||
| * @since 5.8 | ||
| */ | ||
| type SearchIndexDefinition = com.mongodb.client.model.SearchIndexDefinition | ||
|
|
||
| /** | ||
| * A vector search index definition. | ||
| * @since 5.8 | ||
| */ | ||
| type VectorSearchIndexDefinition = com.mongodb.client.model.VectorSearchIndexDefinition | ||
|
|
||
| /** | ||
| * A factory for defining fields within a vector search index definition. | ||
| * @since 5.8 | ||
| */ | ||
| type VectorSearchIndexFields = com.mongodb.client.model.VectorSearchIndexFields | ||
|
|
||
| /** | ||
| * Options for the HNSW indexing method in a vector search index. | ||
| * @since 5.8 | ||
| */ | ||
| type HnswSearchIndexOptions = com.mongodb.client.model.HnswSearchIndexOptions |
Comment on lines
24
to
33
| /** | ||
| * A model describing the creation of a single Atlas Search index. | ||
| * | ||
| * <p>The {@code definition} parameter accepts any {@link org.bson.conversions.Bson} instance. | ||
| * For vector search indexes, use the builders provided by {@link SearchIndexDefinition#vectorSearch(Bson...)} | ||
| * and {@link VectorSearchIndexFields} to construct the definition.</p> | ||
| * | ||
| * @see SearchIndexDefinition | ||
| * @see VectorSearchIndexFields | ||
| * @since 4.11 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JAVA-6112